package com.v5ent.mongo4j.web;

import com.v5ent.mongo4j.entity.User;
import com.v5ent.mongo4j.service.UserService;
import com.v5ent.mongo4j.web.vo.Result;
import com.v5ent.mongo4j.web.vo.ResultCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public Result findAll(){
        return new Result(ResultCode.SUCCESS,userService.findAll());
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable Long id){
        User u =  userService.findById(id);
        return  new Result(ResultCode.SUCCESS,u);
    }

    @RequestMapping(method = RequestMethod.POST)
    public Result update(@RequestBody User user){
        userService.update(user);
        return new Result(ResultCode.SUCCESS);
    }
   
}
